package com.yuneec.fly.utils;

import android.util.SparseIntArray;

import java.util.ArrayList;

/**
 * Created by gjw on 2016/12/1.
 */

public class ChannelUtils {


    public static final int HW_INDEX_BASE_J = 0;
    public static final int HW_INDEX_BASE_K = 10;
    public static final int HW_INDEX_BASE_T = 20;
    public static final int HW_INDEX_BASE_S = 30;
    public static final int HW_INDEX_BASE_B = 50;
    public static final int HW_INDEX_BASE_TTS = 70;
    public static final int HW_INDEX_BASE_TTB = 90;

    public static final String HARDWARE_NAME_1 = "J1";
    public static final String HARDWARE_NAME_2 = "J2";
    public static final String HARDWARE_NAME_3 = "J3";
    public static final String HARDWARE_NAME_4 = "J4";
    public static final String HARDWARE_NAME_5 = "K1";
    public static final String HARDWARE_NAME_6 = "K2";
    public static final String HARDWARE_NAME_7 = "K3";
    public static final String HARDWARE_NAME_8 = "S1";
    public static final String HARDWARE_NAME_9 = "S2";
    public static final String HARDWARE_NAME_10 = "S3";
    public static final String HARDWARE_NAME_11 = "S4";
    public static final String HARDWARE_NAME_12 = "S5";
    public static final String HARDWARE_NAME_13 = "B1";
    public static final String HARDWARE_NAME_14 = "B2";
    public static final String HARDWARE_NAME_15 = "B3";
    public static final String HARDWARE_NAME_16 = "B4";

    public static final int FMODE_KEY_INDEX = HW_INDEX_BASE_B;
    public static final int BIND_KEY_INDEX = HW_INDEX_BASE_B + 1;
    public static final int AUX_KEY_INDEX = HW_INDEX_BASE_B + 2;
    public static final int CAMERA_KEY_INDEX = HW_INDEX_BASE_B + 3;
    public static final int VIDEO_KEY_INDEX = HW_INDEX_BASE_B + 4;
    public static final int ZOOM_KEY_INDEX = HW_INDEX_BASE_K;
    public static final int SONAR_KEY_INDEX = HW_INDEX_BASE_S + 3;

    public static SparseIntArray HW_CHANNEL_INDEX = new SparseIntArray();

    static {
        HW_CHANNEL_INDEX.put(HW_INDEX_BASE_J + 1, 0);
        HW_CHANNEL_INDEX.put(HW_INDEX_BASE_J + 2, 1);
        HW_CHANNEL_INDEX.put(HW_INDEX_BASE_J + 3, 2);
        HW_CHANNEL_INDEX.put(HW_INDEX_BASE_J + 4, 3);
        HW_CHANNEL_INDEX.put(HW_INDEX_BASE_K + 1, 4);
        HW_CHANNEL_INDEX.put(HW_INDEX_BASE_K + 2, 5);
        HW_CHANNEL_INDEX.put(HW_INDEX_BASE_K + 3, 6);
        HW_CHANNEL_INDEX.put(HW_INDEX_BASE_S + 1, 7);
        HW_CHANNEL_INDEX.put(HW_INDEX_BASE_S + 2, 8);
        HW_CHANNEL_INDEX.put(HW_INDEX_BASE_S + 3, 9);
        HW_CHANNEL_INDEX.put(HW_INDEX_BASE_S + 4, 10);
        HW_CHANNEL_INDEX.put(HW_INDEX_BASE_S + 5, 11);
        HW_CHANNEL_INDEX.put(HW_INDEX_BASE_B + 1, 12);
        HW_CHANNEL_INDEX.put(HW_INDEX_BASE_B + 2, 13);
        HW_CHANNEL_INDEX.put(HW_INDEX_BASE_B + 3, 14);
        HW_CHANNEL_INDEX.put(HW_INDEX_BASE_B + 4, 15);
    }

    public static float getChannelValue(int[] channels, int hardwareIndex) {
        float value = 0;
        if (hardwareIndex == HW_INDEX_BASE_J || hardwareIndex == HW_INDEX_BASE_K || hardwareIndex == HW_INDEX_BASE_T
                || hardwareIndex == HW_INDEX_BASE_S || hardwareIndex == HW_INDEX_BASE_B
                || hardwareIndex == HW_INDEX_BASE_TTS || hardwareIndex == HW_INDEX_BASE_TTB) {
            return value;
        }
        return channels[HW_CHANNEL_INDEX.get(hardwareIndex)];
    }
}
